Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-new-target

Package Overview
Dependencies
Maintainers
4
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-new-target

Transforms new.target meta property

  • 8.0.0-alpha.13
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25M
increased by5.48%
Maintainers
4
Weekly downloads
 
Created

What is @babel/plugin-transform-new-target?

The @babel/plugin-transform-new-target npm package is designed to transform instances of the `new.target` meta-property within functions. This is particularly useful for compiling ES6 code to be compatible with environments that do not support the `new.target` syntax. The `new.target` property is used within constructors to determine if the constructor was called with the `new` operator, allowing constructors to identify how they were invoked and to behave differently if necessary.

What are @babel/plugin-transform-new-target's main functionalities?

Transforming new.target

This feature allows the transformation of `new.target` usage into a form that can be understood by environments that do not support this syntax. It checks if the constructor was called with `new` and throws an error if it wasn't, ensuring that the constructor behaves as intended even in older JavaScript environments.

function MyConstructor() {\n  if (!new.target) {\n    throw 'MyConstructor must be called with new';\n  }\n  console.log('MyConstructor was called with new');\n}\n// Transformed Code:\nfunction MyConstructor() {\n  var _newtarget = this instanceof MyConstructor ? this.constructor : void 0;\n  if (!_newtarget) {\n    throw 'MyConstructor must be called with new';\n  }\n  console.log('MyConstructor was called with new');\n}

Other packages similar to @babel/plugin-transform-new-target

Keywords

FAQs

Package last updated on 25 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc